
<#include "/base/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
				            
			            	<span class="search_item">
				            	<span class="item_text">名称：</span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" addClear type="text" name="name" id="name" value="" data-options=""></input>
				            	</span>    
				            </span>
				            
			            	<span class="search_item">
				            	<span class="item_text">bo类：</span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" addClear type="text" name="boPath" id="boPath" value="" data-options=""></input>
				            	</span>    
				            </span>
				            
		        		
        </div>
        <div style="text-align: left; margin:6px;">
        	<!--  
            -->
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-eye-open" plain="true" onclick="validateBo()">验证BO</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-random" plain="true" onclick="mackConfig()">生成配置 </a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-cog" plain="true" onclick="mainConfig()">主配置</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-asterisk" plain="true" onclick="sonConfig()">子配置</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-text-size" plain="true" onclick="mackCodeTest()">生成测试代码</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-remove" plain="true" onclick="deleteTestFile()">删除测试代码</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-duplicate" plain="true" onclick="mackCodeFinal()">生成正式代码</a>
            
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch()">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
            
        </div>
    </div>
    
<script type="text/javascript">

//数据表格初始化参数
var dgOptions = {
        rownumbers:true, //显示行号
    	fit:true, //自适应父容器
    	border:false, //是否显示面板边框。
    	url:'listData',  //数据请求URL
    	method:'post', //请求方式
    	toolbar:'#tb', //工具栏
    	pageSize: 20, //每页数量
    	pagination:true, //显示分页
    	//fitColumns:true, //自动调整各列宽度。当为true时，各列的宽度值只是一个比例。
    	striped:true, //是否显示斑马线
    	multiSort:false, //是否允许多列排序
		sortName:'addTime', //初始排序字段
		sortOrder:'desc', //初始排序方式
    	singleSelect: true, //是否单选
		ctrlSelect : true, //启用多选时，允许使用Ctrl键+鼠标进行多选
		showFooter : true, //是否显示行脚
        queryParams: zcurdGetParam(), //请求参数
        onDblClickRow:function(index, row){dbClickShow(row.id);}, //双击行事件
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'code', title: '编号', width:60, align:'center',sortable:true}
	           	 ,{field:'boPath', title: 'bo类', width:260, align:'left',sortable:true}
	           	 ,{field:'name', title: '显示名称', width:80, align:'center'}
	           	 ,{field:'tdNum', title: '列数', width:80, align:'center'}
	           	 ,{field:'validated', title: '通过验证', width:80, align:'center', formatter:formatBoolean1}
	           	 ,{field:'buildConfig', title: '生成配置', width:80, align:'center', formatter:formatBoolean3}
	           	 ,{field:'config', title: '完成主配置', width:80, align:'center', formatter:formatBoolean1}
	           	 ,{field:'configField', title: '完成子配置', width:80, align:'center', formatter:formatBoolean1}
	           	 ,{field:'urlTest', title: '测试预览', width:80, align:'center', formatter:formatUrlTest}
	           	 ,{field:'urlFinal', title: '正式地址', width:280, align:'left', formatter:formatUrlFinal}
	           	 ,{field:'remark', title: '备注', width:200, align:'center'}
	           	 ,{field:'addTime', title: '创建时间', width:130, align:'center',sortable:true}
	           	 
	           ]],
	      loadFilter: function(data) {
	        	   if(data.result && data.result == 'fail') {	//失败时，错误消息提示
	        		   showWarnMsg(data.msg);
	        		   return {};
	        	   }else {
	        		   return data;
	        	   }
	           }           
	};



var datagrid = $("#dg"); //数据表格

$(function() {
	datagrid.datagrid(dgOptions); //绘制数据表格
	autoAddClear(); //为各组件自动填加‘清除’功能（组件需要增加 addClear属性 ）
});

//查询
function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", param)
}

//获取查询参数
function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	//console.log(param);
	return param;
}

var initPara = zcurdGetParam(); //初始化参数，主要目的是保存一些隐藏条件

//增加
function add() {
	top.window.subPage.loadCurrDatagrid = function() { //设置成功后的回调方法
		datagrid.datagrid("load");
	}
	top.openWindow("增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '500x320'});
}

//修改
function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.datagrid("reload");
	}
	top.openWindow("编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '500x320'});
}

//详情
function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	dbClickShow(id);
}

//双击打开查看
function dbClickShow(id) {
	top.openWindow_view("详情", getCurrUrl("detailPage") + "?id=" + id, {size: '500x300'});
}

//删除
function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据");
		return;
	}
	confirmMsg("确认删除?", function() {
		$.post(getCurrUrl("delete"), {ids: ids.join(",")}, function(data) {
			
			if("01" == data.code){//成功
				datagrid.datagrid("reload");
				showMsg(data.msg); //显示消息
			}else if("04" == data.code){//失败
				showErrorMsg(data.msg); //显示错误消息
			}
			
		});
	});
}

//验证BO
function validateBo() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据");
		return;
	}

	var callBackFun = function() { //设置回调方法
		datagrid.datagrid("load");
	}
	
	var id = rowsSel[0].id;
	top.openWindow_view("验证BO", getCurrUrl("validateBo") + "?id=" + id, {size: '500x320'}, callBackFun);
}

//生成配置
function mackConfig() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据");
		return;
	}

	var callBackFun = function() { //设置回调方法
		datagrid.datagrid("load");
	}
	
	confirmMsg("确认生成配置?", function() {
		var id = rowsSel[0].id;
		top.openWindow_view("生成配置", getCurrUrl("mackConfig") + "?id=" + id, {size: '500x320'},callBackFun);
	});
}

//主配置
function mainConfig() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据");
		return;
	}
	
	if(!rowsSel[0].buildConfig)
	{
		showWarnMsg("请先【生成配置】");
		return;
	}
	
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.datagrid("reload");
	}
	
	var id = rowsSel[0].id;
	top.openWindow("主配置", getCurrUrl("mainConfigPage") + "?id=" + id, {size: '430x490'});
}


//子配置
function sonConfig() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据");
		return;
	}
	
	if(!rowsSel[0].buildConfig)
	{
		showWarnMsg("请先【生成配置】");
		return;
	}
	
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.datagrid("reload");
	}
	var id = rowsSel[0].id;
	top.openWindow("子配置", getCurrUrl("sonConfigPage") + "?id=" + id, {size: '1000x600'});
	
	top.window.$('#dialogWindow').window('maximize'); //最大化

}

//生成测试代码
function mackCodeTest()
{
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据");
		return;
	}
	
	if(!rowsSel[0].config || !rowsSel[0].configField )
	{
		showWarnMsg("请先完成【主配置】和【子配置】");
		return;
	}

	var callBackFun = function() { //设置回调方法
		datagrid.datagrid("load");
	}
	confirmMsg("生成代码将会直接【覆盖】以前的代码！<br/>确认生成测试代码?", function() {
		var id = rowsSel[0].id;
		top.openWindow_view("生成测试代码", getCurrUrl("mackCodeTest") + "?id=" + id, {size: '500x320'}, callBackFun);
	});
	
}

//生成运行代码
function mackCodeFinal()
{
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据");
		return;
	}
	
	if(!rowsSel[0].config || !rowsSel[0].configField )
	{
		showWarnMsg("请先完成【主配置】和【子配置】");
		return;
	}

	var callBackFun = function() { //设置回调方法
		datagrid.datagrid("load");
	}
	confirmMsg("确认生成正式代码?", function() {
		var id = rowsSel[0].id;
		top.openWindow_view("生成正式代码", getCurrUrl("mackCodeFinal") + "?id=" + id, {size: '500x320'}, callBackFun);
	});
	
}

//生成运行代码
function deleteTestFile()
{
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据");
		return;
	}
	
	if(!rowsSel[0].config || !rowsSel[0].configField )
	{
		showWarnMsg("请先完成【主配置】和【子配置】");
		return;
	}

	var callBackFun = function() { //设置回调方法
		datagrid.datagrid("load");
	}
	confirmMsg("确认删除测试代码?", function() {
		var id = rowsSel[0].id;
		top.openWindow_view("生成正式代码", getCurrUrl("deleteTestFile") + "?id=" + id, {size: '400x200'}, callBackFun);
	});
	
}


//测试预览
function previewTest(index) {
	var row = datagrid.datagrid("getRows")[index];
	top.window.addMainTab("[测试] " + row.name, "${basePath}" + row.urlTest );
}

//正式预览
function previewFinal(index) {
	var row = datagrid.datagrid("getRows")[index];
	top.window.addMainTab("[正式] " + row.name, "${basePath}" + row.urlFinal );
}

/**
 * 格式化函数
 */

//测试URL
function formatUrlTest(value, row, index)
{
	if(value == null)
	{
		return "";
	}
	return '<a class="operate" href="javascript:void(0)" onclick="previewTest(' + index + ')" style="color:#00F">测试预览</a>' ;
};

//正式URL
function formatUrlFinal(value, row, index)
{
	if(value == null)
	{
		return "";
	}
	return '<a class="operate" href="javascript:void(0)" onclick="previewFinal(' + index + ')" style="color:#00F">正式预览</a> ' +row.urlFinal;
};

//Boolean 是否
function formatBoolean1(value)
{
	if(value == null)
	{
		return "";
	}
	if(value)
	{
		return "是";
	}
	return "<span style='color:#ff0000'>否</span>";
	
};

function formatBoolean3(value)
{
	if(value == null)
	{
		return "";
	}
	if(value)
	{
		return "已生成";
	}
	return "<span style='color:#ff0000'>未生成</span>";
	
};


</script>

<#include "/base/common/dialogWindow.html"/>
<#include "/base/common/foot.html"/>
